﻿using AiXiu.BLL;
using AiXiu.Model;
using Newtonsoft.Json;
using System.Web;

namespace AiXiu.WebSite.Handler
{
    /// <summary>
    /// UploadVideoHandler 的摘要说明
    /// </summary>
    public class UploadVideoHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // 读取参数
            string filename = HttpUtility.UrlDecode(context.Request.QueryString["filename"]);
            string title = HttpUtility.UrlDecode(context.Request.QueryString["headline"]);
            if (string.IsNullOrWhiteSpace(title))
            {
                title = "短视频";
            }
            string location = HttpUtility.UrlDecode(context.Request.QueryString["location"]);
            // 读取用户Id
            TBUsers user = IdentityManager.ReadUser();
            int userId = user.Id;
            // 媒体处理
            VideoBLL videoBLL = new VideoBLL();
            CreateUploadVideoResult result = videoBLL.uploadVideo(title, filename, location, userId);
            // 输出
            string jsonString = JsonConvert.SerializeObject(result);
            context.Response.ContentType = "text/plain";
            context.Response.Write(jsonString);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}